<!DOCTYPE html>
<script>
if (window.testRunner) {
  testRunner.dumpAsText();
  testRunner.waitUntilDone();
}
webkitRequestFileSystem(TEMPORARY, 0, gotFS, onError.bind(null, 'requestFileSystem'));

function gotFS(fs) {
  fs.root.getFile('foo', {create: true}, gotEntry, onError.bind(null, 'getFile'));
}

function gotEntry(entry) {
  entry.file(gotFile.bind(null, entry), onError.bind(null, 'file'));
  if (window.gc)
    gc();
}

var firstGotFile = true;
function gotFile(entry, file) {
  if (firstGotFile) {
    firstGotFile = false;
    setTimeout(gotEntry.bind(null, entry), 0);
    return;
  }
  var reader = new FileReader();
  reader.onerror = onError.bind(null, 'FileReader');
  reader.onloadend = function() {
    if (window.testRunner) {
      document.body.innerText = 'PASS';
      testRunner.notifyDone();
    }
  };
  reader.readAsText(file);
}

function onError(msg, e) {
  document.body.innerText = 'FAIL: ' + msg;
  if (window.testRunner)
    testRunner.notifyDone();
}

</script>
